package day9;

import java.util.ArrayList;
import java.util.Scanner;

import org.junit.Test;

import day4.Teacher;

public class demo2 {
	

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入教师个数：");
		Integer num = scanner.nextInt();
		//Teacher[] teachers = new Teacher[num];
		ArrayList<Teacher> list = new ArrayList<Teacher>();//Teacher 是在括号里
		for (;;) {
			
				System.out.println("请输入教师id:");
				int id = scanner.nextInt();
				System.out.println("请输入教师名字：");
				String name = scanner.next();
				System.out.println("请输入教师年龄：");
				int age = scanner.nextInt();
				System.out.println("请输入教师班级：");
				String className = scanner.next();
				System.out.println("请输入教师收入：");
				double salary = scanner.nextInt();
				Teacher teacher = new Teacher(id, age, name, className, salary);
				//teacher.setId(id);
				//teacher.setName(name);
				//teacher.setAge(age);
				//teacher.setClassName(className);
				//teacher.setSalary(salary);
				list.add(teacher);
				System.out.println("退出请输入0");
				Integer quit = scanner.nextInt();
				if(quit == 0) {
					break;
				}
			}
		
		for (Teacher teacher : list) {
			
			
			
			//输出，引用函数tostring
			System.out.println(teacher.toString());
	
			
			
		}	
				
			
			
			
			
	
		
		
		
		
		
		while(true) {
			System.out.println("-----------------");
			System.out.println("依据id查找请输入1：");
			System.out.println("依据姓名查找请输入2：");
			System.out.println("依据年龄查找请输入3；");
			System.out.println("依据班级查找请输入4:");
			System.out.println("依据薪水查找请输入5：");
			System.out.println("退出请输入0");
			System.out.println("-----------------");
			Integer type = scanner.nextInt();
			if(type == 0) {
				System.out.println("退出");
				break;
				
			}
			
			switch(type) {
			case 1:
				System.out.println("请输入需要查找的老师id：");
				boolean isExistId = false;
				for (Teacher teacher : list) {
					Integer id = scanner.nextInt();
				
					if (teacher.getId() == id) {
						isExistId = true;
						System.out.println(teacher.toString());
					}
					
				}
				if (isExistId == false) {
					System.out.println("查不到此人信息");
				}
				break;
			case 2:
				System.out.println("请输入需要查找的老师名字：");
				boolean isExistName = false;//bool假设找不到
				for (Teacher teacher : list) {
					String name = scanner.next();//对应输出的字符串
					//Teacher teacher = teachers[i];//将对象从数组中拿出来
					if (name.equals(teacher.getName())) {//比较用equals：变量.equals（）括号里用get函数方法调用						
						
						isExistName = true;//存在即需要输出对象信息
						System.out.println(teacher.toString());
					}
					
				}//结束循环判定是否boolean类型结果是否发生变化
				if (isExistName == false) {
					System.out.print("查无此人信息");
				}
				break;
			case 3:
				System.out.println("请输入需要查找的老师年龄：");
				boolean isExistAge = false;
				for (Teacher teacher : list) {
					//Teacher teacher = teachers[i];
					Integer age = scanner.nextInt();
					if (teacher.getAge() == age) {
						isExistAge = true;
						System.out.print(teacher.toString());
					}
				}
				if (isExistAge == false) {
					System.out.print("查无此人信息");
				}
				break;
			case 4:
				System.out.print("请输入需要查找的老师班级：");
				boolean isExistClassName = false;
				for (Teacher teacher : list) {
					//Teacher teacher = teachers[i];
					String className = scanner.next();
					
					if (className.equals(teacher.getClassName())) {
						
						System.out.print(teacher.toString());
					}
				}
				if (isExistClassName == false) {
					
					System.out.println("查无此人");
					
				}
				break;
			case 5:
				System.out.println("请输入需要查找老师的薪水：");
				boolean isExistSalary = false;
				for (Teacher teacher : list) {
					//Teacher teacher = teachers[i];
					Double salary = (double) scanner.nextInt();
					if (teacher.getSalary() == salary) {
						isExistSalary = true;
						System.out.print(teacher.toString());
						
					}
				}
				if (isExistSalary == false) {
					System.out.print("查无此人");
				}
				break;
			default:
				break;
				
				
			}
			
		}
		}
  
	@Test
	public void test11() {
		Teacher teacher = new Teacher(1, 5, "554", "45", (double) 14);
		teacher.teach();
		teacher.show();
	}

}
